//
//  GarbageListVC.swift
//  Community
//
//  Created by MAC on 2019/8/2.
//  Copyright © 2019 ZKJ. All rights reserved.
//

import UIKit

class SWPTGarbageListVC: UIViewController {

    lazy var tableView: UITableView = {
        let tableView = UITableView.init(frame: .zero)
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(SWPTGarbageListCell.nib(), forCellReuseIdentifier: SWPTGarbageListCell.identifier)
        tableView.separatorStyle = .none
        return tableView
    }()
    
    
    private var images: [String] = []
    private var dataSource: [String] = []
    
    //["gan","shi","huishou","youhai"]
     var index: Int = 0 // 0干  1湿垃圾    2可回收  3有害
   private  var headerView: SWPTGarbageListHeaderView!
    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = .white
        
        self.view.addSubview(tableView)
        
        tableView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        headerView = SWPTGarbageListHeaderView.loadFromNib()
        self.tableView.tableHeaderView = headerView
        
        
        headerView.snp.makeConstraints { (make) in
            make.height.equalTo(225)
            make.width.equalTo(kScreenW)
            make.left.top.equalToSuperview()
        }
        setupData()
        
    }
    
    private func setupData() {
        let titles = ["干垃圾","湿垃圾","可回收垃圾","有害垃圾"]
        self.headerView.title.text = titles[index]
        switch index {
        case 0:
            ganlaji()
        case 1:
            shilaji()
        case 2:
            kehuishou()
        case 3:
            youhai()
        default:
            break
        }
        
        var datas:[SWPTGarbage] = []
        for (idx,image) in images.enumerated() {
            let garbage = SWPTGarbage(name: dataSource[idx], image: image)
            datas.append(garbage)
        }
        
        headerView.garbages = datas
        self.tableView.reloadData()
    }
    
    private func shilaji() {
        images = [
            "1224561","1218434","1231539","1181470",
            "1233152","1213154","1233190","1219209",
        ]
        dataSource = [
            "包子","面包","饼干","方便面",
            "果皮","汉堡","螃蟹","树叶",
            "食物残渣","菜根","菜叶","动物蹄",
            "角","瓜皮","果屑","蛋壳",
            "鱼鳞","鱼鳞","毛发","植物枝干",
            "杂草","动物尸体","牲畜粪便"
        ]
        
    }
    
    private func ganlaji() {
        images = [
            "1192088","1209821","1227417","1214044",
            "1204531","1218247","1224939","1225424",
        ]
        dataSource = [
            "雨伞","镜子","毛巾","笔",
            "橡皮擦","椰子壳","打火机","眼镜",
            "橡胶制品","尿不湿","瓦陶瓷","渣土",
            "卫生间废纸","瓷器碎片","回形针","餐盒",
            "餐巾纸","湿纸巾","口香糖","口红",
            "隐形眼镜","美瞳","尿不湿","卫生间用纸",
            "塑料袋","烟蒂","纸尿裤","一次性杯子",
            "大骨头","贝壳","花盆陶瓷","猫砂",
            "化妆刷"
        ]
        
    }
    
    private func kehuishou() {
        let gar = SWPTGarbage.init(name: "isnameaok", image: "image")
        let garar = SWPTGarbage.init(name: "isnamsseaok", image: "xmafimage")
        images = [
            "1227595","1227335","1234840","1227614",
            "1228367","1216093","1207488","1232329",
        ]
        dataSource = [
            "信用卡","笔记本电脑","拖鞋","耳机",
            "手机","衣服","钻石","运动鞋",
            "废纸张","废塑料","废玻璃","废金属",
            "废织物","牙刷","易拉罐","饮料瓶",
            "洗发水瓶","塑料玩具","书本","报纸",
            "纸板箱","衣服","床上用品","玻璃杯",
            "塑料瓶","食品罐头","旧书包","旧手提包",
            "旧鞋子","牛奶盒","旧玩偶","玻璃壶",
            "旧铁锅"
        ]
        
    }
    
    private func youhai() {
        images = [
            "1224831","1213445","1235395","1145698",
            "1185784","1216951","1232558","1232579",
        ]
        dataSource = [
            "蓄电池","医疗废弃物","胶卷","药瓶",
            "油漆","温度计","照片","指甲油",
            "废灯管","荧光灯管","废药品","杀虫剂",
            "医用纱布","医用棉签","打火机","创口贴",
            "酒精","调色板油漆","过期药片","水彩笔",
            "农药瓶","口服液瓶","香水瓶","荧光棒",
            "过期化妆品"
        ]
        
    }
    
    

}

extension SWPTGarbageListVC: UITableViewDataSource, UITableViewDelegate {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataSource.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: SWPTGarbageListCell.identifier) as! SWPTGarbageListCell
        if indexPath.row % 2 == 0 {
            cell.bgView.backgroundColor = UIColor.groupTableViewBackground
        }else {
            cell.bgView.backgroundColor = UIColor.white
        }
        cell.name.text = self.dataSource[indexPath.row]
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    
        return 44
    }
}
